<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

      <!-- 搜寻框内部 begin -->
        <!-- id查询 -->
        <a-col :xl="5" :lg="7" :md="8" :sm="24">
          <a-form-item label="订单编号：">
            <a-input placeholder="请输入订单编号" v-model="queryParam.id"></a-input>
          </a-form-item>
        </a-col>

        <a-col :xl="5" :lg="7" :md="8" :sm="24">
          <a-form-item label="模块名称：">
            <a-input placeholder="请输入模块名称" v-model="queryParam.moduleName"></a-input>
          </a-form-item>
        </a-col>

        


        <!-- 查询，重置按钮 -->
        <span class="searchButtons">
          <a-button @click="searchQuery" type="primary" icon="search">查询</a-button>
          <a-button @click="searchReset" type="primary" icon="reload" style="margin-left:10px">重置</a-button>
        </span>


        <!-- 搜寻框内部 end -->
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('供养订单表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <temple-donation-order-modal ref="modalForm" @ok="modalFormOk"></temple-donation-order-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import TempleDonationOrderModal from './modules/TempleDonationOrderModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { getAction } from '../../../api/manage'
 import { filterObj } from '@/utils/util'

  export default {
    name: 'TempleDonationOrderList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      TempleDonationOrderModal
    },
    data () {
      return {
  
       //查询参数
       queryParam:{
          //订单id
          id:"",
          moduleName:"",
          
       },
        
        //翻页信息
        //设置翻页信息
      ipagination:{
          current:1,
          pageSize:10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
          },
        //   isorter: {
        //   column: 'amount',
        //   order: 'desc'
        // },
        description: '供养订单表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'项目名称',
            align:"center",
            dataIndex: 'donationId_dictText'
          },
          {
            title:'项目类型',
            align:"center",
            dataIndex: 'donationTypeId_dictText'
          },
          {
            title:'模块名称',
            align:"center",
            dataIndex: 'moduleName'
          },
          {
            title:'微信昵称',
            align:"center",
            dataIndex: 'userId_dictText',
            customRender:(text)=>(text ? decodeURIComponent(text) : ''),
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'手机号',
            align:"center",
            dataIndex: 'mobile'
          },
          {
            title:'是否公开',
            align:"center",
            dataIndex: 'isOpen',
            customRender: (text) => (text ? filterMultiDictText(this.dictOptions['isOpen'], text) : ''),
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'金额',
            align:"center",
            dataIndex: 'amount'
          },
          {
            title:'是否已支付',
            align:"center",
            dataIndex: 'isPay',
            customRender: (text) => (text ? filterMultiDictText(this.dictOptions['isPay'], text) : ''),
          },
          {
            title:'支付渠道',
            align:"center",
            dataIndex: 'payChannel_dictText'
          },
          {
            title:'支付凭证',
            align:"center",
            dataIndex: 'payVoucher',
            scopedSlots: {customRender: 'imgSlot'}
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          // list: "/temple.order/templeDonationOrder/list",
          delete: "/temple.order/templeDonationOrder/delete",
          deleteBatch: "/temple.order/templeDonationOrder/deleteBatch",
          exportXlsUrl: "/temple.order/templeDonationOrder/exportXls",
          importExcelUrl: "temple.order/templeDonationOrder/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.$set(this.dictOptions, 'isOpen', [{text:'是',value:'true'},{text:'否',value:'false'}])
      this.$set(this.dictOptions, 'isPay', [{text:'是',value:'Y'},{text:'否',value:'N'}])
    // this.getSuperFieldList();
    this.loadData();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      //页面载入数据获取
      async loadData(arg)
      {
          if(arg==1)
        {
          this.ipagination.current=1;  
        }
        
        var param = this.getQueryParam();
        this.loading = true;
        
        //返回axios对象
        getAction('/temple.order/templeDonationOrder/list',param).then(res=>{
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }

          // var sysOrgCode=this.userInfo.orgCode
          // this.dictCondition= '{"sys_org_code":"'+sysOrgCode+'"}'
          // console.log(this.dictCondition)
        }).finally(() => {
          this.loading = false
        })
      },
      //获取查询参数
      getQueryParam(){
       var param = Object.assign({}, this.queryParam);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        return filterObj(param);
      },
      //获取查询范围
      getQueryField(){
        let str = '';
        for(let a =0;a<this.columns.length;a++)
        {
          str += ','+ this.columns[a].dataIndex;
        }
        return str;
      },
      //条件查询 
      //查询
      searchQuery(){
        this.loadData();
      },
      //重置
      searchReset(){
        var that = this;
        this.queryParam = {};
        that.loadData(this.ipagination.current);
      },

      initDictConfig(){
      },
      // getSuperFieldList(){
      //   let fieldList=[];
      //   fieldList.push({type:'string',value:'donationId',text:'项目id',dictCode:"temple_donation,name,id"})
      //   fieldList.push({type:'string',value:'donationTypeId',text:'项目类型',dictCode:"temple_donation_type,name,id"})
      //   fieldList.push({type:'string',value:'moduleId',text:'模块id',dictCode:"temple_donation_module,name,id"})
      //   fieldList.push({type:'string',value:'moduleName',text:'模块名称',dictCode:''})
      //   fieldList.push({type:'string',value:'userId',text:'用户id',dictCode:"temple_user,nick_name,id"})
      //   fieldList.push({type:'string',value:'name',text:'姓名',dictCode:''})
      //   fieldList.push({type:'string',value:'mobile',text:'手机号',dictCode:''})
      //   fieldList.push({type:'switch',value:'isOpen',text:'是否公开'})
      //   fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
      //   fieldList.push({type:'BigDecimal',value:'amount',text:'金额',dictCode:''})
      //   fieldList.push({type:'switch',value:'isPay',text:'是否已支付'})
      //   fieldList.push({type:'string',value:'payChannel',text:'支付渠道',dictCode:''})
      //   fieldList.push({type:'string',value:'payVoucher',text:'支付凭证',dictCode:''})
      //   this.superFieldList = fieldList
      // }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>